// -*- C++ -*-

//=============================================================================
/**
*  @file    Service_Type_Impl.h
*
*	@date    2009-12-18 11:20
*
*  @author wing <totti19851101@gmail.com>
*/
//=============================================================================

#ifndef _SERVICE_TYPE_IMPL_H_
#define _SERVICE_TYPE_IMPL_H_

#include "Pre.h"
#include "Shared_Object.h"

typedef void (*Service_Object_Exterminator)(void *);

/**
* @class Service_Type_Impl
*
* @brief The abstract base class of the hierarchy that defines the
* contents of the Service_Repository.  The subclasses of
* this class allow the configuration of Service_Objects,
* Modules, and Streams.
*
* This class provides the root of the implementation hierarchy
* of the "Bridge" pattern.  It maintains a pointer to the
* appropriate type of service implementation, i.e.,
* Service_Object, Module, or Stream.
*/

class Service_Type_Impl
{
public:
	Service_Type_Impl( void* object,
					const char* s_name,
					u_int flags = 0,
					Service_Object_Exterminator gobbler = 0
					);
	virtual ~Service_Type_Impl(void);

	// = Pure virtual interface( must be defined by the subclass )
	virtual int suspend(void) const = 0;
	virtual int resume(void) const = 0;
	virtual init( int argc, char* argv[] ) const = 0;
	virtual fini(void) const;
	virtual info( char** str, size_t len ) const = 0;

	/// The pointer to the service.
	void *object (void) const;

	/// The pointer to the service.
	void char* name( void ) const;

	/// Set the name of the service.
	void name( const char* );

	/// Dump the state of an object.
	void dump(void) const;

protoent:
	/// Name of the service.
	const char* name_;

	/// Pointer to object that implements the service.This actually
	/// pointers to an Service_Object, Module, or Stream.
	void* obj_;

	/// Destroy function to deallocate obj_.
	Service_Object_Exterminator gobbler_;

	/// Flags that control service behavior( particulary deletion )
	u_int flags_;
};

/**
* @class Service_Object_Type
*
* @brief Define the methods for handling the configuration of
* Service_Objects.
*/
class Service_Object_Type : public Service_Type_Impl
{
public:
	// = Initalization methods.
	Service_Object_Type( void* so,
						const char* name,
						u_int flags = 0,
						Service_Object_Exterminator gobbler = 0);
	~Service_Object_Type(void);

	// = Implement the hook for <Service_Objects>.
	virtual int suspend(void) const;
	virtual int resume(void) const;
	virtual int init( int argc, char* argv[] ) const;
	virtual int fini( void ) const;
	virtual int info( char** str, size_t len ) const;
};

#include "Post.h"
#endif//_SERVICE_TYPE_IMPL_H_